#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
#   GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#   Author :  Shawn.Tan
#   Date : 2025.10.28
#
#   History : Initial Version 2025.10.28
#
#
import Log
import traceback


def assert_true(expression, msg=""):
    if not expression:
        err_msg = "%s is false. %s" % (str(expression), msg)
        log_failure(err_msg)


def assert_false(expression, msg=""):
    if expression:
        err_msg = "%s is true. %s" % (str(expression), msg)
        log_failure(err_msg)


def assert_equal(left, right, msg=""):
    if left != right:
        err_msg = "%s != %s. %s" % (str(left), str(right), msg)
        log_failure(err_msg)


def assert_less_equal(left, right, msg=""):
    if left > right:
        err_msg = "%s > %s. %s" % (str(left), str(right), msg)
        log_failure(err_msg)


def assert_greater_equal(left, right, msg=""):
    if left < right:
        err_msg = "%s < %s. %s" % (str(left), str(right), msg)
        log_failure(err_msg)


def assert_not_in(elem, container, msg=""):
    if elem in container:
        err_msg = "%s is in %s. %s" % (str(elem), str(container), msg)
        log_failure(err_msg)


def log_failure(err_msg):
    stack_frame_str = get_stack_frame_string()
    Log.fail("%s\n%s" % (err_msg, stack_frame_str))


def get_stack_frame_string():
    stack_frames = traceback.format_list(traceback.extract_stack())
    stack_frame_str = "".join(stack_frames[:-1])
    return stack_frame_str
